<template>
  <div>
    <!-- 新增修改表单 -->
    <el-dialog
      width="50%"
      :title="textMap[dialogStatus]"
      :visible.sync="DialogFormVisibleCom"
      append-to-body
    >
      <div class="myfrom1002">
        <el-form ref="dataForm" :rules="rules" :model="formSubmitDataCom" label-position="right" label-width="110px"
                 style="width: 90%; margin:10px auto;">
          <el-row :gutter="20">

            <el-col :span="12">
              <el-form-item label="节点名称">
                <el-input
                  v-model="sonCurrentRow.coa_name"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="节点编号">
                <el-input
                  v-model="sonCurrentRow.coa_code"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <!-- 客户行为 -->
            <el-col :span="12">
              <el-form-item label="客户行为" prop="cust_action">
                <el-select
                  v-model="formSubmitDataCom.cust_action"
                  class="filter-item"
                  placeholder="Please select"
                  :disabled="false"
                >
                  <el-option v-for="item in custActionOptions" :key="item.code" :label="item.name" :value="item.code"/>
                </el-select>
              </el-form-item>
            </el-col>

            <!-- 罚息计算日 -->
            <el-col :span="12">
              <el-form-item label="罚息计算日" prop="pm_date_type">
                <el-select
                  v-model="formSubmitDataCom.pm_date_type"
                  class="filter-item"
                  placeholder="Please select"
                  :disabled="false"
                >
                  <el-option v-for="item in pmDatetypeOptions" :key="item.code" :label="item.name" :value="item.code"/>
                </el-select>
              </el-form-item>
            </el-col>


          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatus==='udateSave'?updateSaveData():updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import XEUtils from 'xe-utils'
import {filterAllRowBynormData} from '@/utils/index'

export default {
  name: 'PricingSubmitForm',
  components: {
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
    formSubmitData: {
      type: Object,
      default: function () {
        return {}
      }
    },
    /* 当前选中方案 */
    currentRow: {
      type: Object,
      default() {
        return {}
      }
    },
    /* 当前选中节点 */
    sonCurrentRow: {
      type: Object,
      default() {
        return {}
      }
    },
    /* 客户信息Options */
    custActionOptions: {
      type: Array,
      default(){
        return []
      }
    },
    /* 罚息计算日Options */
    pmDatetypeOptions:{
      type: Array,
      default(){
        return []
      }
    }
  },
  // 定义属性
  data() {
    return {
      textMap: {
        update: '修改',
        create: '新增',
        udateSave: '客户行为-更新&保存'
      },
      rules: {
        // tp_id: [{required: true, message: '期限方案必填', trigger: 'change'}],
        // s_date: [{validator: validateDateRangeSdate, trigger: 'change'}],
        // e_date: [{validator: validateDateRangeEdate, trigger: 'change'}],
        // type: [{ required: true, message: 'type is required', trigger: 'change' }],
        // timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        // title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    },
  },
  // 监控data中的数据变化
  watch: {
  },
  // 方法集合
  methods: {
    resetFormData() {
      let exclude = []
      // if (this.dialogStatus === 'create') {
      //   exclude = [
      //     'cv_name',
      //     'curr_name',
      //     'e_date'
      //   ]
      // }
      // console.log('this.dialogStatusthis.dialogStatus', this.dialogStatus);
      // if (this.dialogStatus === 'update') {
      //   exclude = [
      //     'cv_name',
      //     'curr_name',
      //     'tp_id'
      //   ]
      // }
      // console.log('exclude', exclude);

      this.$emit('resetFormDataEmit', {
        exclude
      })

    },

    updateSaveData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromUpdateSaveDataEmit')
        }
      })
    },

    // updateData() {
    //   this.$refs['dataForm'].validate((valid) => {
    //     if (valid) {
    //       const tempData = Object.assign({}, this.formSubmitData)
    //       this.$emit('handlePricingFromUpdateDataEmit')
    //       // tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
    //       // updateArticle(tempData).then(() => {
    //       //   const index = this.list.findIndex(v => v.id === this.temp.id)
    //       //   this.list.splice(index, 1, this.temp)
    //       //   this.dialogFormVisible = false
    //       //   this.$notify({
    //       //     title: 'Success',
    //       //     message: 'Update Successfully',
    //       //     type: 'success',
    //       //     duration: 2000
    //       //   })
    //       // })
    //     }
    //   })
    // },

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    console.log('formSubmitDataformSubmitData222', this.formSubmitData);
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>
.myfrom1002 {
  ::v-deep {
    .el-col-12 {
      height: 58px;
    }

  }
}


</style>